package com.hy.lightning.boot.service;

import java.io.IOException;
import java.io.InputStream;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

import org.apache.commons.io.IOUtils;

import com.hy.lightning.boot.annotation.RespType;
import com.hy.lightning.boot.core.ContentType;
import com.hy.lightning.boot.core.ServiceConfiguration;
import com.hy.lightning.boot.core.ServicesFactory;

public class Boot {

	@RespType(ContentType.TEXT_HTML)
	public String services() throws IOException {
		InputStream in = ClassLoader.getSystemResourceAsStream("com/hy/lightning/boot/service/services.html");
		String text = new String(IOUtils.toByteArray(in));
		if(in != null) {
			in.close();
		}
		return text;
	}
	
	/**
	 * 获取服务配置信息
	 * @return
	 */
	public Map<String,ServiceConfiguration> getServiceConfigurations() {
		Map<String,ServiceConfiguration> sortMap = new TreeMap<String, ServiceConfiguration>(new Comparator<String>() {

			@Override
			public int compare(String o1, String o2) {
				return o1.compareTo(o2);
			}
		});
        sortMap.putAll(ServicesFactory.servicesCache);
        return sortMap;
	}
}
